'use strict';
app.factory('ShoppingService', function(HttpUtilService,$q,APPCONSTANT) {
        /***
         * 获取轮播图
         * @param carousel_type int 1-首页轮播图、2-品牌馆轮播图
         * @returns {AnimateRunner.promise|*|qFactory.Deferred.promise|td.f.promise|f.promise}
         * 点击进入产品详情
         *{
         * gooods_id int 产品编号
         * picture 图片地址
         * }
         */
        function getCarousel (carousel_type){
          var version = APPCONSTANT.version;
            var deferred = $q.defer();
            HttpUtilService.httpPostNoToken("Index/Carousel",{version:version,carousel_type:carousel_type}).then(function (response) {
              if(response.code == "000000"){
                deferred.resolve(response.data)
              } else {
                console.log("getCarousel:"+ response)
              }
            },function (error) {
              console.log("getCarousel error:"+ error)
            })
            return deferred.promise;
        }

        /***
         * 获取活动的4个展示图片
         * @returns {AnimateRunner.promise|*|qFactory.Deferred.promise|td.f.promise|f.promise}
         * 点击进入模块
         * {
         * type int 1-BargainPrice（天天疯抢），2-GroupBuy （爱拼团），3-Valueble（值得买），4-brandList（品牌馆）
         * picture 图片地址
         * }
         */
        function getActivity (){
          var version = APPCONSTANT.version;
            var deferred = $q.defer();
            HttpUtilService.httpPostNoToken("Index/Activity",{version:version})
                .then(function (response) {
                    if(response.code == "000000"){
                        deferred.resolve(response.data)
                    } else {
                        console.log("getActivity:"+ response)
                    }
                },function (error) {
                    console.log("getActivity error:"+ error)
                })
            return deferred.promise;
        }

        /***
         * 获取产品宣传图
         * @param current_page int 当前页数
         * @param items_per_page int 一页显示几条数据
         * @returns {AnimateRunner.promise|*|qFactory.Deferred.promise|td.f.promise|f.promise}
         * 点击图片进入产品详情页
         * {
         * goods_id int 产品编号
         * picture 图片地址
         * }
         */
        function getBanner (current_page,items_per_page){
          var version = APPCONSTANT.version;
            var deferred = $q.defer();
                HttpUtilService.httpPostNoToken("Index/Beaner",{current_page:current_page,items_per_page:items_per_page,version:version})
                .then(function (response) {
                    if(response.code == "000000"){
                        deferred.resolve(response.data)
                    } else {
                        console.log("getBanner:"+ response)
                    }
                },function (error) {
                    console.log("getBanner error:"+ error)
                })
            return deferred.promise;
        }

        /***
         * 获取爱拼团数据
         * @param current_page
         * @param items_per_page
         * @param version
         * @returns {AnimateRunner.promise|*|qFactory.Deferred.promise|td.f.promise|f.promise}
         * {
         * goods_id int 产品编号
         * goods_title 产品标题
         * cat_id int 商品分类id
         * goods_description 产品描述
         * goods_price float 商品原价
         * real_price float 实付金额
         * buyers_nums int 商品数量
         * group_price 团购价，包括规模价格
         * alone_price int 单独买
         * more string 更多地址，同样更多参数
         * picture 图片地址
         * }
         */
        function getGroupBuy (current_page,items_per_page){
          var version = APPCONSTANT.version;
            var deferred = $q.defer();
           HttpUtilService.httpGetNoToken("GroupBuy/Request",{current_page:current_page,items_per_page:items_per_page,version:version})
                .then(function (response) {
                    if(response.code == "000000"){
                        deferred.resolve(response.data)
                    } else {
                        console.log("getGroupBuy:"+ response)
                    }
                },function (error) {
                    console.log("getGroupBuy error:"+ error)
                })
            //var data =[{goods_id:1,goods_title:'澳大利亚麦丽素2盒装360g*2盒',cat_id:1,goods_description:'澳大利亚麦丽素2盒装360g*2盒,惊喜多多等你来拿！限时抢购！',
            //    goods_price:299,real_price:88.4,buyers_nums:1189,group_price:88.4,alone_price:98,picture:'img/home/share_GoodsOne.jpg'}];
            //deferred.resolve(data);
            return deferred.promise;
        }

        /***
         * 同类更多团购商品
         * @param more
         * @param current_page int 页数
         * @param items_per_page int rows
         * @param version
         * @returns {AnimateRunner.promise|*|qFactory.Deferred.promise|td.f.promise|f.promise}
         * {
         * 内容同上
         * }
         */
        function getGroupBuyMore (more,current_page,items_per_page){
          var version = APPCONSTANT.version;
            var deferred = $q.defer();
            HttpUtilService.httpPostNoToken("GroupBuy/More",{more:more,current_page:current_page,items_per_page:items_per_page,version:version})
                .then(function (response) {
                    deferred.resolve(response.data)
                },function (error) {
                    console.log("getCarousel error:"+ error)
                })
            return deferred.promise;
        }

        /***
         * 获取推荐商品
         * @param cat_id int
         * @param user_id int
         * @param current_page int
         * @param items_per_page int
         * @param version
         * @returns {AnimateRunner.promise|*|qFactory.Deferred.promise|td.f.promise|f.promise}
         * * {
         * goods_id int 产品编号
         * goods_tite 产品标题
         * cat_id int 商品分类id
         * goods_description 产品描述
         * goods_price float 商品原价
         * real_price float 实付金额
         * buyers_nums int 商品数量
         * group_price 团购价，包括规模价格
         * alone_price int 单独买
         * rebate int 折扣率
         * buy_count int 已购买人数
         * picture 图片地址
         * }
         */
        function getRecommend (cat_id,user_id,current_page,items_per_page){
          var version = APPCONSTANT.version;
            var deferred = $q.defer();
            HttpUtilService.httpGetNoToken("GroupBuy/Recommend",{cat_id:cat_id,user_id:user_id,current_page:current_page,items_per_page:items_per_page,version:version})
                .then(function (response) {
                    deferred.resolve(response.data)
                },function (error) {
                    console.log("getRecommend error:"+ error)
                })
            return deferred.promise;
        }

        /***
         * 获取天天疯抢
         * @param current_page
         * @param items_per_page
         * @param version
         * @returns {AnimateRunner.promise|*|qFactory.Deferred.promise|td.f.promise|f.promise}
         * {
         * goods_id int 产品编号
         * goods_tite 产品标题
         * cat_id int 商品分类id
         * goods_description 产品描述
         * goods_price float 商品原价
         * real_price float 实付金额
         * buyers_nums int 商品数量
         * group_price 团购价，包括规模价格
         * alone_price int 单独买
         * more 更多地址
         * time 时间
         * picture 图片地址
         * }
         */
        function getBargainPrice (current_page,items_per_page){
          var version = APPCONSTANT.version;
            var deferred = $q.defer();
            HttpUtilService.httpGetNoToken("BargainPrice/Query",{current_page:current_page,items_per_page:items_per_page,version:version})
                .then(function (response) {
                    if(response.code == "000000"){
                        deferred.resolve(response.data)
                    } else {
                        console.log("getBargainPrice:"+ response)
                    }
                },function (error) {
                    console.log("getBargainPrice error:"+ error)
                })
            return deferred.promise;
        }

        /***
         * 获取产品宣传广告
         * @param current_page
         * @param items_per_page
         * @param version
         * @returns {AnimateRunner.promise|*|qFactory.Deferred.promise|td.f.promise|f.promise}
         * {
         * goods_id int 产品编号
         * goods_tite 产品标题
         * cat_id int 商品分类id
         * goods_description 产品描述
         * goods_price float 商品原价
         * real_price float 实付金额
         * buyers_nums int 商品数量
         * group_price 团购价，包括规模价格
         * alone_price int 单独买
         * picture 图片地址
         * }
         */
        function getValuebleBanner (current_page,items_per_page){
          var version = APPCONSTANT.version;
            var deferred = $q.defer();
            HttpUtilService.httpPostNoToken("Valueble/Beaner",{current_page:current_page,items_per_page:items_per_page,version:version})
                .then(function (response) {
                    if(response.code == "000000"){
                        deferred.resolve(response.data)
                    } else {
                        console.log("getValuebleBanner:"+ response)
                    }
                },function (error) {
                    console.log("getValuebleBanner error:"+ error)
                })
            return deferred.promise;
        }
        return {
            getCarousel:getCarousel,
            getActivity:getActivity,
            getBanner:getBanner,
            getGroupBuy:getGroupBuy,
            getGroupBuyMore:getGroupBuyMore,
            getRecommend:getRecommend,
            getBargainPrice:getBargainPrice,
            getValuebleBanner:getValuebleBanner
        }
    })
